package com.example.common;

//controller统一返回包装类  ，这个便于前后端数据交互
//前端获取后端controller层接口返回的JSON格式的数据，并展示出来。通常为了提高代码质量，会将后端返回的数据进行统一的格式处理。

public class Result {
    private static final String ERROR_CODE = "250";
    private static final String SUCCESS_CODE = "100";

    private String code;
    private String msg;
    private Object data;   //数据统统被包装在data中返回

    public Result(String code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result() {
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }


    public static Result success(Object data){
        return new Result(SUCCESS_CODE,"", data);
    }

    public static Result success(){
        return new Result(SUCCESS_CODE,"");
    }

    public static Result error(String msg){
        return new Result(ERROR_CODE,"", msg);
    }


}
